from django.shortcuts import render
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets
from rest_framework.filters import SearchFilter
from rest_framework.pagination import PageNumberPagination

from one.models import Type, Company
from one.ser import TypeSerializer, CompanySerializer


# Create your views here.
class Page(PageNumberPagination):
    page_size = 2
    page_size_query_param = 'size'
    page_query_param = 'page'
class TypeViews(viewsets.ModelViewSet):
    queryset = Type.objects.all()
    serializer_class = TypeSerializer
class CompanyViews(viewsets.ModelViewSet):
    queryset = Company.objects.all()
    serializer_class = CompanySerializer
    pagination_class = Page
    filter_backends = [DjangoFilterBackend, SearchFilter]
    filterset_fields = ['type']
    search_fields = ['job_number', 'department']